<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-07-24 13:59:42
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-07-24 14:41:35
 * @Description: 终审
 * 
-->
<template>
	<el-dialog
		:title="'终审'"
		v-model="visible"
		:width="700"
		destroy-on-close
		@closed="$emit('closed')"
	>
		<el-form
			:model="form"
			:rules="rules"
			ref="dialogForm"
			label-width="100px"
			label-position="right"
		>
			<el-row>
				<el-col :span="12">
					<el-form-item label="客户">
						<el-input
							v-model="form.company.name"
							readonly
						></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="产品" prop="material_id">
						<skAutoChoose
							v-model="form.material.name"
							:name="'material'"
							:assign="form"
							:prepend_width="'60px'"
							@select="materialSelect"
							:browserShow="false"
							:params="[{ material_nature_id: 3 }]"
						>
							<template #prepend>{{
								form.material.spec
							}}</template>
						</skAutoChoose>
					</el-form-item>
				</el-col>

				<el-col :span="12">
					<el-form-item label="色号">
						<el-input v-model="form.main.code" readonly></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="色名">
						<el-input v-model="form.main.name" readonly></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="贸易色号">
						<el-input v-model="form.code_my" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>

		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()"
				>保 存</el-button
			>
		</template>
	</el-dialog>
</template>

<script>
import tool from "@/utils/tool";
import skAutoChoose from "@/components/skAutoChoose";
export default {
	emits: ["success", "closed"],
	components: { skAutoChoose },
	data() {
		return {
			form: {
				main: {},
				material: {},
				company: {},
				lot: {},
			},
			rules: {
				material_id: { required: true, message: "品名必填" },
			},
			visible: false,
			isSaveing: false,
		};
	},
	mounted() {},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this;
		},
		materialSelect(data) {
			this.form.material = data;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.pro.color.auditGood.post({
						id: this.form.id,
						code_my: this.form.code_my,
						material_id: this.form.material_id,
					});
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit("success", this.form, this.mode);
						this.visible = false;
						this.$message.success("操作成功");
					}
				}
			});
		},
		//表单注入数据
		setData(data) {
			Object.assign(this.form, tool.removeNull(data));
		},
	},
};
</script>

<style></style>
